package top.wenzz.manage.system.manage.entity;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;
import top.wenzz.commons.annotation.Edit;
import top.wenzz.commons.annotation.Query;
import top.wenzz.commons.entity.DataEntity;

import javax.persistence.*;
import javax.persistence.Entity;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by cui_fate on 2016/9/6.
 */
@Entity( name = "sys_role" )
@Data
public class SysRole extends DataEntity<SysRole> {
    @Column(name="role_name", length = 50, unique = true, nullable = false)
    @Length(min = 2, max = 50, message = "角色名称长度为2-50")
    @NotBlank(message = "角色名称不能为空")
    @Edit("角色名称")
    @Query(Query.ReadType.LIKE)
    private String name;

    @ManyToMany
    @JoinTable(name = "sys_role_authority", joinColumns = {@JoinColumn(name = "role_id")}, inverseJoinColumns = {@JoinColumn(name = "authority_id")})
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private List<SysPermission> permissions = new ArrayList<>();
}
